﻿<MudPopoverProvider />

<MudSelect Label="Select Item"
           MultiSelection="true"
           T="@TestItem"
           SelectedValues="@_selectedItems"
           ToStringFunc="@ToString">
    @foreach (var item in _allItems)
    {
        <MudSelectItem Value="@item" />
    }
</MudSelect>

@code {
    private readonly List<TestItem> _allItems = [];
    private readonly HashSet<TestItem> _selectedItems = [];

    protected override async Task OnInitializedAsync()
    {
        _allItems.Add(new TestItem { A = "FirstA" });
        _allItems.Add(new TestItem { A = "SecondA" });
        _allItems.Add(new TestItem { A = "ThirdA" });
        
        _selectedItems.Add(_allItems[0]);
        _selectedItems.Add(_allItems[1]);
        await base.OnInitializedAsync();
    }

    private static string ToString(TestItem? x) => x is null ? string.Empty : $"{x.A}";

    private class TestItem
    {
        public required string A { get; init; }        
    }
}
